package com.authine.cloudpivot.common.extension.defaultextension;

import com.alibaba.cola.dto.SingleResponse;
import com.authine.cloudpivot.common.extension.client.dto.AttachmentDTO;
import com.authine.cloudpivot.common.extension.client.dto.AttachmentRes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.io.ByteArrayInputStream;

/**
 * 文件服务扩展点默认扩展实现
 * <p>
 * 请勿修改任何类和方法的定义
 * <p>
 * 只需要在方法内部编写业务逻辑
 */
@Api(tags = "文件服务扩展点")
@Slf4j
@RestController
@RequestMapping("/file/v1")
public class FileExtensionController {

    @ApiOperation(value = "文件上传")
    @ApiImplicitParam(name = "attachmentRes", value = "附件对象")
    @PostMapping("/upload")
    public SingleResponse<String> uploadFile(@RequestBody AttachmentDTO attachmentRes) {
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(attachmentRes.getBytes());
        log.info("二开上传附件...{}", attachmentRes.getFileName());
        // TODO 编写二开代码
        return SingleResponse.of(null);
    }

    @ApiOperation(value = "文件下载")
    @ApiImplicitParam(name = "refId", value = "文件资源id")
    @GetMapping(value = "/download")
    public SingleResponse<AttachmentRes> downloadFile(@RequestParam(name = "refId") String refId) {
        log.info("二开下载附件...{}", refId);
        // TODO 编写二开代码
        return SingleResponse.of(null);
    }

    @ApiOperation(value = "文件删除")
    @ApiImplicitParam(name = "refId", value = "文件资源id")
    @GetMapping(value = "/delete")
    public SingleResponse<Boolean> deleteByRefId(@RequestParam(name = "refId") String refId) {
        log.info("二开删除附件...{}", refId);
        // TODO 编写二开代码
        return SingleResponse.of(true);
    }

    @ApiOperation(value = "删除资源目录对象")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bucketName", value = "命名空间"),
            @ApiImplicitParam(name = "objectName", value = "目录名称")
    })
    @GetMapping(value = "/remove_objects")
    public SingleResponse<Boolean> removeObjects(@RequestParam(name = "bucketName") String bucketName, @RequestParam(name = "objectName") String objectName) {
        log.info("二开removeObjects...{}, {}", bucketName, objectName);
        // TODO 编写二开代码
        return SingleResponse.of(true);
    }

}
